package org.hq.security.contryoller;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import java.security.Security;
import java.util.Collection;

@Controller
public class IndexConroller {
    /**
     * 首页
     * @return
     */
    @GetMapping("/index")
    public String index(){
        //获取当前登录用户信息
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();
        //用户信息
        Object Principal = authentication.getPrincipal();
        //用户凭证
        Object credentials = authentication.getCredentials();
        Collection<? extends GrantedAuthority> collection = authentication.getAuthorities();
        System.out.println("Principal = "+Principal);
        System.out.println("credentials = "+credentials);
        return "index";
    }

    /**
     * 用户登录页面
     * @return
     */
    @GetMapping("/login")
    public String login(){
        return "login";
    }
    /**
     * 用户登录失败页面
     * @return
     */
    @GetMapping("/error")
    public String error(){
        return "error";
    }
}
